﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication3.Search
{
    using Reports;
    using Reports.companypaymentdatasetTableAdapters;
    public partial class SearchCompanyPayment : Form
    {
        public SearchCompanyPayment()
        {
            InitializeComponent();
            fillpaymenttable();
        }
       
        public void fillpaymenttable()
        {

            Companypaymenttableadapter adapt = new Companypaymenttableadapter();

            adapt.Connection = new OleDbConnection(Program.ConnStr);//This is not mandatory.just to confirm.

            DataTable dt = adapt.getalldata();

            tblcompanypayment.DataSource = dt;


        }

        private void tblcompanypayment_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (tblcompanypayment.SelectedRows.Count == 0)
            {

            }
            else
            {
                int rowno = tblcompanypayment.CurrentCellAddress.Y;
                int paymentpk = int.Parse(tblcompanypayment.Rows[rowno].Cells[0].Value.ToString());

                fillDatagridByPk(paymentpk);
                this.Close();
                this.Dispose();
               

            }
        }


        public void fillDatagridByPk( int paymentpk)
        {
            companypaymentreportTableAdapter adapt = new companypaymentreportTableAdapter();
            adapt.Connection = new OleDbConnection(Program.ConnStr);
            DataTable dt = adapt.GetDataByPaymentPk(paymentpk);
            tblcompanypayment.DataSource = dt;
            CompanyPaymentReport cmpnypayrpt = new CompanyPaymentReport();
            cmpnypayrpt.SetDataSource((DataTable)dt);
            CompanyPaymentReportForm rptform = new CompanyPaymentReportForm();
            rptform.reportsource = cmpnypayrpt;
            rptform.ShowDialog();
            
        }

        private void SearchCompanyPayment_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'companypaymentdataset.DataTable1' table. You can move, or remove it, as needed.
            this.companypaymenttableadapter.Fill(this.companypaymentdataset.DataTable1);

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {

            Companypaymenttableadapter adapt = new Companypaymenttableadapter();

            adapt.Connection = new OleDbConnection(Program.ConnStr);//This is not mandatory.just to confirm.
            int paymentpk = int.Parse(cmbjobcode.SelectedValue.ToString());

            DataTable dt = adapt.GetDataByPaymentpk(paymentpk); ;

            tblcompanypayment.DataSource = dt;
            

        }










    }
}
